#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define MAXN 100
int edge[MAXN][MAXN];

struct vertex
{
	int id;
	int deg;
};


vertex ver[MAXN];

bool cmp(const vertex & a,const vertex & b)
{
	return a.deg>b.deg;
}

int main()
{
	int t;
	int n;
	int i,j;
	cin>>t;
	while(t--){
		memset(edge,0,sizeof(edge));
		cin>>n;
		for(i=0;i<n;i++){
			ver[i].id=i+1;
			cin>>ver[i].deg;
		}
		
		j=0;
		bool flag=true;
		 
		while(j<n){
			sort(ver+j,ver+n,cmp);
			if(ver[j].deg>n-j-1){
				flag=false;
				break;
			}
			for(i=j+1;i<=j+ver[j].deg;i++){
				ver[i].deg--;
				if(ver[i].deg<0){
					flag=false;
					break;
				}
				edge[ver[j].id][ver[i].id]=1;
				edge[ver[i].id][ver[j].id]=1;
				
			}
			if(!flag) break; 
			j++;
		}
		if(flag){
			cout<<"YES"<<endl; 
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					cout<<edge[i][j]<<" ";
				}
				cout<<endl;
			}
		}
		else{
			cout<<"NO"<<endl;
		}
		
		
	} 
} 
